﻿using System.Collections.Generic;
using Tutorial;
using XLua;
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif

namespace XLua.CSObjectWrap
{
    using Utils = XLua.Utils;

    public class TutorialBaseClassWrap
    {
        public static void __Register(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
            System.Type type = typeof(Tutorial.BaseClass);
            Utils.BeginObjectRegister(type, L, translator, 0, 2, 1, 1);

            Utils.RegisterFunc(L, Utils.METHOD_IDX, "BMFunc", _m_BMFunc);
            Utils.RegisterFunc(L, Utils.METHOD_IDX, "GetSomeBaseData", _m_GetSomeBaseData);

            Utils.RegisterFunc(L, Utils.GETTER_IDX, "BMF", _g_get_BMF);

            Utils.RegisterFunc(L, Utils.SETTER_IDX, "BMF", _s_set_BMF);

            Utils.EndObjectRegister(type, L, translator, null, null, null, null, null);

            Utils.BeginClassRegister(type, L, __CreateInstance, 2, 1, 1);
            Utils.RegisterFunc(L, Utils.CLS_IDX, "BSFunc", _m_BSFunc_xlua_st_);

            Utils.RegisterFunc(L, Utils.CLS_GETTER_IDX, "BSF", _g_get_BSF);

            Utils.RegisterFunc(L, Utils.CLS_SETTER_IDX, "BSF", _s_set_BSF);

            Utils.EndClassRegister(type, L, translator);
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int __CreateInstance(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 1)
                {
                    var gen_ret = new Tutorial.BaseClass();
                    translator.Push(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return LuaAPI.luaL_error(L, "invalid arguments to Tutorial.BaseClass constructor!");
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_BSFunc_xlua_st_(RealStatePtr L)
        {
            try
            {
                {
                    Tutorial.BaseClass.BSFunc();

                    return 0;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_BMFunc(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                Tutorial.BaseClass gen_to_be_invoked = (Tutorial.BaseClass)
                    translator.FastGetCSObj(L, 1);

                {
                    gen_to_be_invoked.BMFunc();

                    return 0;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _m_GetSomeBaseData(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                Tutorial.BaseClass gen_to_be_invoked = (Tutorial.BaseClass)
                    translator.FastGetCSObj(L, 1);

                {
                    var gen_ret = gen_to_be_invoked.GetSomeBaseData();
                    LuaAPI.xlua_pushinteger(L, gen_ret);

                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_BMF(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                Tutorial.BaseClass gen_to_be_invoked = (Tutorial.BaseClass)
                    translator.FastGetCSObj(L, 1);
                LuaAPI.xlua_pushinteger(L, gen_to_be_invoked.BMF);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_BSF(RealStatePtr L)
        {
            try
            {
                LuaAPI.xlua_pushinteger(L, Tutorial.BaseClass.BSF);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_BMF(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                Tutorial.BaseClass gen_to_be_invoked = (Tutorial.BaseClass)
                    translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.BMF = LuaAPI.xlua_tointeger(L, 2);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_BSF(RealStatePtr L)
        {
            try
            {
                Tutorial.BaseClass.BSF = LuaAPI.xlua_tointeger(L, 1);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }
    }
}
